<template>
  <div class="mod-poapweb__poapnews">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('poapweb:poapnews:save')" type="primary" @click="addOrUpdateHandle()">{{
          $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('poapweb:poapnews:delete')" type="danger" @click="state.deleteHandle()">{{
          $t("deleteBatch") }}</el-button>
      </el-form-item>
      <el-form-item>
  </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border
      @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="title" label="新闻标题" header-align="center" align="center"></el-table-column>
      <!-- <el-table-column prop="abstracts" label="摘要" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="visits" label="访问量" header-align="center" align="center"></el-table-column>
      <el-table-column prop="pubDate" label="发布时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="status" label="状态" sortable header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.status === 0" size="small" type="danger">{{ $t("user.status0") }}</el-tag>
          <el-tag v-else size="small" type="success">{{ $t("user.status1") }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="摘要" header-align="center" align="center">
        <template v-slot="scope">
          <el-button type="text"  @click="abstractsShow(scope.row)">查看新闻摘要</el-button>
        </template>
      </el-table-column>
      <el-table-column label="新闻内容" header-align="center" align="center">
        <template v-slot="scope">
          <el-button type="text" @click="bodyShow(scope.row)">查看内容</el-button>
        </template> 
      </el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('poapweb:poapnews:update')" type="primary" link
            @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="state.hasPermission('poapweb:poapnews:delete')" type="primary" link
            @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
      :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle"
      @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
    <el-dialog v-model="abstractsVisible" width="50%" top="200px">
      <p>{{ abstractsUrl }}</p>
    </el-dialog>
    <el-dialog v-model="bodyVisible" width="50%" top="10px">
      <div v-html="bodyUrl"></div>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./poapnews-add-or-update.vue";
import poapNotice from "./poapNotice.vue";
import { useRouter } from "vue-router";
import { values } from "lodash";
const router = useRouter();
const abstractsVisible = ref(false);
const abstractsUrl = ref("");


const abstractsShow = (row: any) => {
  abstractsVisible.value = true;
  abstractsUrl.value = row.abstracts
}

const bodyVisible = ref(false);
const bodyUrl = ref("");

const bodyShow = (row: any) => {
  bodyVisible.value = true;
  bodyUrl.value = row.ossBody
}
const view = reactive({
  getDataListURL: "/poapweb/poapnews/listAllByLabel",
  getDataListIsPage: true,
  exportURL: "/poapweb/poapnews/export",
  deleteURL: "/poapweb/poapnews",            
  deleteIsBatch: true,
  dataForm: {}
});

const state = reactive({ ...useView(view), ...toRefs(view) ,dataForm: {dictValue:1}})
const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(id);
  });
};
</script>
